<?php
/****************************************************************************************
 * Build Head
 ****************************************************************************************/

# php self = script php name ----------------------------------------------
	preg_match('/.*\/(.*)\.php/', $_SERVER['PHP_SELF'], $scriptName);
	$GLOBALS["php_self"] = $scriptName[1];
	
# uri ---------------------------------------------------------------------
	$GLOBALS["uri"] = ltrim($_SERVER['REQUEST_URI'],'/');
	
# page in address bar -----------------------------------------------------
	if(strpos($GLOBALS["uri"], '/')!==false){
	  $tmp = explode('/', $GLOBALS["uri"]);
	  $GLOBALS["page"] = $tmp[0];
	}elseif(strpos($GLOBALS["uri"], '?')!==false){
	  $tmp = explode('?', $GLOBALS["uri"]);
	  $GLOBALS["page"] = $tmp[0];
	} else {
	  $GLOBALS["page"] = $GLOBALS["uri"];
	}

# uri-self and request-query -----------------------------------------------
	list($GLOBALS["uri_self"], $GLOBALS["request_query"]) = explode('?', $_SERVER['REQUEST_URI']);

#	define the css/js/helper files will be included ------------------------
	$cssNames = array('header', 'footer', 'menu', 'common', 'search');
	$jsNames = array('env', 'common', 'menu');
	$helperNames = array('session', 'html', 'string');
	
	switch($GLOBALS["php_self"]) {
	  case 'help':
			array_push($cssNames, 'help');
			break;
	  
		case 'advertisement':
			array_push($cssNames, 'advertisement');
			array_push($helperNames, 'pagination', 'url');
			break;
		
		case 'advertisement-new':
			array_push($cssNames, 'advertisement-new');
			array_push($jsNames, 'advertisement-new');
			array_push($helperNames, 'image', 'validator');
			break;
			
		case 'advertisement-add':
			array_push($cssNames, 'advertisement-add');
			array_push($helperNames, 'image', 'mail');
			break;

		case 'advertisement-show':
			array_push($cssNames, 'advertisement-show');
			array_push($jsNames, 'advertisement-show', 'validator');
			array_push($helperNames, 'validator');
			break;
			
		case 'success':
		  array_push($cssNames, 'success');
	}

# include the helpers --------------------------------------------------------------------
	foreach($helperNames as $helperName) {
    require_once HELPER_PATH.$helperName.'.helper.php';
  }
?>